﻿using System;
using System.IO;
using NUnit.Framework;
using Smartkernel;
using Smartkernel.IO;

namespace Smartkernel.NUnitTest.IO
{
    [Category("IO")]
    [TestFixture]
    public class SmartSerializeTest
    {
        [Test]
        public void Test()
        {
            //【01】序列化对象（涉及方法：Serialize）
            string path = Environment.CurrentDirectory + @"\SmartSerialize_NUnitTest\person.bin";
            Person person = new Person();
            person.Name = "曹艳白";
            person.BirthDay = DateTime.Parse("1982-05-02");
            SmartSerialize.Serialize(person, path, SmartSerializeType.Binary);

            //【02】串行化对象（涉及方法：Deserialize）
            Person otherPerson = SmartSerialize.Deserialize<Person>(path, SmartSerializeType.Binary);
            Assert.AreEqual(otherPerson.Name, "曹艳白");
            Directory.Delete(Environment.CurrentDirectory + @"\SmartSerialize_NUnitTest", true);
        }

        [Serializable]
        private class Person
        {
            public string Name;
            public DateTime BirthDay;
        }
    }
}
